<style lang="less">
@import '../../../assets/style/yhqx_list.less';
</style>

<template>
	<mxq-router-layout>
		<div class="qxyh_list quexian_list">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<span>缺陷查看</span>
				</div>
				<div slot="headerRight"  v-show="showHide">
					<span v-if="this.$route.query.towerStatus==0">
						<i class="iconfont icon-shouye"/>
					</span>
					<span v-else>新增</span>
				</div>
			</Head>

			<!--有数据时-->
			<GanTaList
				style="padding-bottom:75px;"
				v-if="qxLists && qxLists.length >= 0"
				:gantaList="qxLists"
				:picUrlLeft="picUrlLeft"
				@clickList="clickList($event)"
			>
				<template slot="titles" slot-scope="item">
					<span class="iconBox">
						<img
							:src="picUrlRight"
							alt=""
							class="arrow"
						>
					</span>
				</template>
			</GanTaList>

			<!--无数据时-->
			<div v-if="qxLists  && qxLists.length == 0" class="cont_box">
				<img class="pic_zanwu" src="../../../assets/img/changguixunshi/icon_zanwu.png" alt="">
				<p class="text_zanwu">暂无历史缺陷哦！！！</p>
			</div>
			<span  v-if="this.$route.query.towerStatus==0"></span>
			<van-tabbar v-else>
				<van-button size="large" type="primary" class="btn_list_sure" @click="confirm">确定</van-button>
			</van-tabbar>
			<!-- <van-tabbar>
				<van-button size="large" type="primary" class="btn_list_sure"  v-show="isShow" @click="confirm">确定</van-button>
			</van-tabbar> -->
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '@/components/head'
import GanTaList from '../../../components/ganta-list'
import IconQX from '../../../assets/img/icon_qx.png'
import IconJT from '../../../assets/img/changguixunshi/icon_jt.png'
import { callData } from '../../../axios/axios'

import {
	Cell,
	CellGroup,
	Button,
	Icon,
	Tabbar,
	TabbarItem,
	Toast
} from 'vant'

export default {
    name: 'quexianList',
    components: {
		Head,
		GanTaList,
		[Button.name]:Button,
		[Icon.name]: Icon,
		[Tabbar.name]: Tabbar,
		[TabbarItem.name]: TabbarItem
	},
	data() {
		return {
			showHide:true,				//隐藏"新增"
			qxLists:[],					//缺陷列表数据
			picUrlLeft: IconQX,			//列表左侧图标
			picUrlRight: IconJT,		//列表右侧小图标
			isShow: true, 				//是否显示确定按钮
			params: this.$route.query	//获取地址栏参数
		}
	},
	mounted(){
		if(this.params.flag==true){
			Toast('你已经核查过了');
		}
		this.getListData()
		// this.echoImages()
	},
	methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			let query = {}
			this.$router.push({
				name:'bdzs_quexianXinzheng',
				query: {
					childNodeId: this.params.childNodeId,
					name: this.params.name,
					defectType: this.params.defectType,
					towerTaskId: this.params.towerTaskId,
					xsTowerTaskId: this.params.xsTowerTaskId,
					lineTowerId: this.params.lineTowerId,
					taskId: this.params.taskId,
					towerId: this.params.towerId,
					lineId: this.params.lineId,
					jdUserId: this.params.jdUserId,
					phoType: this.params.phoType,
					status: this.params.status,
					towerStatus: this.params.towerStatus,
					needMeasure: this.params.needMeasure,
					index: this.params.index,
					lineName: this.params.lineName,
					towerName: this.params.towerName
				}
			})
		},
		headerClickHome(){
			this.$router.push({name:"index"})
		},
		// 照片回显
 		/*echoImages(){
			var towerId = this.params.towerId,
                status = this.params.status;
			var params = {};
				params.towerId = towerId;
				params.status = status;
				callData("/xsTaskServer/ZcXsTowerTask/getPictures", 'get', params).then(res => {
                    var filePath = res.data.picture;
					var quexian = res.data;
					var defectType = res.data.qx;
                })
		}, */
    	// 隐患列表点击事件
		clickList(e){
			let query = {}
			this.$router.push({
				path:'bdzs_quexianDetail',
				query: {
					name: this.params.name,
					reviewType: e.data.REVIEW_TYPE,
					defectId: e.data.DEFECTID,
                    towerId: this.params.towerId,
                    towerTaskId: this.params.xsTowerTaskId,
                    taskId: this.params.taskId,
                    defectType: this.params.defectType,
                    xsTowerTaskId: this.params.xsTowerTaskId,
                    lineTowerId: this.params.lineTowerId,
                    lineId: this.params.lineId,
                    jdUserId: this.params.jdUserId,
                    phoType: this.params.phoType,
                    status: this.params.phoType,
                    towerStatus: this.params.towerStatus,
					needMeasure: this.params.needMeasure,
					index: this.params.index
				}
			})
		},
		// 确认点击事件
		confirm(){
			var params = {};
			params.towerTaskId = this.params.towerTaskId;		//杆塔任务ID
			params.taskType = this.$route.query.index; 			//任务类型: 0常规巡视 1特殊巡视 2保电值守 3线路检修
			params.towerId = this.params.towerId;				//物理杆塔ID
			params.defectType = this.params.defectType;			//缺陷类型
			callData('/accountServer/CmCheckDefect/addCmCheckDefect', 'post', params).then(res => {
				if(res.success){
					Toast(res.data)
					this.$router.go(-1)
					eventbus.$emit('scrollBottom',1)
				}
				else {
					Toast(res.data)
					// this.$router.go(-1)
				}
			})
		},
		// 获取缺陷列表数据
		getListData(){
			var params = {};
            params.towerId = this.params.towerId;
            params.towerTaskId = this.params.xsTowerTaskId;
            params.taskId = this.params.taskId;
			params.defectType = this.params.defectType;
			callData('/accountServer/CmDefect/findTowerCmDefect', 'get', params).then(res => {
				var qxListData = res.data;
				qxListData.forEach((item,index) => {
					item.textName=item.DEFECT_CHARACTERIZATION;
					// 状态判断
					if (item.REVIEW_TYPE == "0") {
						item.statusName = '复核';
						item.cname = "btn_status";
					}
					else if (item.REVIEW_TYPE == "1") {
						item.statusName = '消缺';
						item.cname = "btn_status1";
					}
					else if (item.REVIEW_TYPE == "2") {
						item.statusName = '新增';
						item.cname = "btn_status3";
					}
					else if (item.REVIEW_TYPE == "3") {
						item.statusName = '待处理';
						item.cname = "btn_status2";
					}
				});
				this.qxLists = qxListData
				// 如果缺陷为选中状态则隐藏确定按钮
				/* if(this.params.flag==true){
					this.isShow = false;
				}
				if(this.params.flag==false){
					this.isShow = true;
				} */
			})
		}
	}
}
</script>